

import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String arg[]) {
        testDownload();
    }

    public static void testUpload() {
        Server server = new Server();
        server.handleUploadFile();
    }

    public static void testDownload() {
        Server server = new Server();
        server.handleDownloadFile();
    }

    public void handleUploadFile() {
        try {
            ServerSocket serverSocket = new ServerSocket(Config.port);
            while (true) {
                Socket socket = serverSocket.accept();
                UploadRunnableImpl uploadRunnableImpl = new UploadRunnableImpl(socket);
                Thread thread = new Thread(uploadRunnableImpl);
                thread.start();
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }

    }

    public void handleDownloadFile() {
        try {
            ServerSocket serverSocket = new ServerSocket(Config.port);
            while (true) {
                Socket socket = serverSocket.accept();
                DownloadRunnableImpl downloadRunnableImpl = new DownloadRunnableImpl(socket);
                Thread thread = new Thread(downloadRunnableImpl);
                thread.start();
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

}

